cmake_minimum_required(VERSION 3.9 FATAL_ERROR)

project(chapter-5-01 LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

add_custom_target(unpack-eigen
    ALL                               # 传递了ALL参数，目标将始终被执行
    COMMAND ${CMAKE_COMMAND} -E tar xzf ${CMAKE_CURRENT_SOURCE_DIR}/eigen-3.4.0.tar.bz2

    # 工作目录
    WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}

    # 指定CMake在执行自定义目标时输出什么样的消息
    COMMENT "Unpacking Eigen3 in ${CMAKE_CURRENT_BINARY_DIR}/eigen-3.4.0"

    # 复制 目录
    COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/config 
    ${CMAKE_CURRENT_BINARY_DIR}/etc

    # 复制文件
    COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/log.txt 
    ${CMAKE_CURRENT_BINARY_DIR}/etc
  )

  add_custom_target(finish
                    COMMAND ${CMAKE_COMMAND} -E echo compile finish)

add_executable(linear-algebra linear-algebra.cpp)

add_dependencies(linear-algebra unpack-eigen)

target_include_directories(linear-algebra
  PRIVATE
    ${CMAKE_CURRENT_BINARY_DIR}/eigen-3.4.0
  )